package com.demo.rabbitmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 广播模式
 * 消费者自动ack
 */
@Slf4j
@Service
public class FanoutConsumer {

    @RabbitListener(id = "fanout_queue_1", queues = "fanout_queue1")
    public void directExchange1(String content) {
        log.info("广播模式，消费者1，消费消息内容：" + content);
    }

    @RabbitListener(id = "fanout_queue_2", queues = "fanout_queue2")
    public void directExchange2(String content) throws InterruptedException {
        TimeUnit.SECONDS.sleep(1);
        log.info("广播模式，消费者2，消费消息内容：" + content);
    }

    @RabbitListener(id = "fanout_queue_3", queues = "fanout_queue3")
    public void directExchange3(String content) throws Exception {
        TimeUnit.SECONDS.sleep(1);
        log.info("广播模式，消费者3，消费消息内容：" + content);
        throw new RuntimeException("消费者3异常");
    }
}
